import 'package:flutter/material.dart';
import 'package:kxy_flutter_app/model/integral_rank.dart';

class DeptRankItemWidget extends StatelessWidget {
  final IntegralRankItem rankItem;
  final bool isLight;

  const DeptRankItemWidget({
    Key key,
    @required this.rankItem,
    this.isLight = false,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 76,
      padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
      child: Row(
        children: [
          index(),
          Expanded(child: name()),
          grade(),
        ],
      ),
    );
  }

  Widget index() {
    return Container(
      width: 40,
      child: Text(
        rankItem.rank > 0 ? rankItem.rank.toString() : '-',
        style: TextStyle(
          fontSize: 16,
          color: isLight ? Colors.white : Colors.black38,
          fontWeight: isLight ? FontWeight.bold : FontWeight.normal,
        ),
      ),
    );
  }

  Widget name() {
    return Text(
      rankItem.deptName,
      style: TextStyle(
        fontSize: 16,
        color: isLight ? Colors.white : Colors.black,
        fontWeight: isLight ? FontWeight.bold : FontWeight.normal,
      ),
    );
  }

  Widget grade() {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.end,
      children: [
        Text(
          rankItem.avgGrade.toString(),
          style: TextStyle(
            fontSize: 16,
            color: isLight ? Colors.amberAccent : Colors.amber,
            fontWeight: isLight ? FontWeight.bold : FontWeight.normal,
          ),
        ),
        Text(
          '分',
          style: TextStyle(
            fontSize: 10,
            color: isLight ? Colors.amberAccent : Colors.amber,
            fontWeight: isLight ? FontWeight.bold : FontWeight.normal,
          ),
        )
      ],
    );
  }
}
